package 笔试记录.百度二面;

public class Mian3 {

    public static void main(String[] args) {
        String s = "abbadef";
        String res = solve(s);
        System.out.println(res);
    }
    public static String solve(String s){
        int Slen = s.length();
        int maxLen = 0;
        String ans = "";
        for(int i = 0;i < Slen;i++){
            for(int j = i + 1;j <= Slen;j++){
                String tmp = s.substring(i,j);
                if(solve2(tmp) && tmp.length() > maxLen){
                    ans = tmp;
                    maxLen = j - i;
                }
            }
        }
        return ans;
    }

    public static boolean solve2(String s){//判断是否是回文串
        int len = s.length();
        StringBuilder str = new StringBuilder(s);
        return s.equals(str.reverse().toString());

    }
}
